package GUI;

import java.awt.*;


public class ChessCanvas extends Canvas implements Runnable{

    String mat[][];
    int alto,ancho,altoFila,anchoFila;
    Image imgBuff;
    Graphics grafBuff;
    
    public void setTablero(String[][] matriz){
        this.mat=matriz;
    }
    
    
    public ChessCanvas(){
        setBackground(Color.white);
    }
    
    public void paint(Graphics g){
        update(g);
    }
    
    @Override
    public void update(Graphics g){
        
        Dimension d= getSize();
        ancho = d.width;
        alto = d.height;
        altoFila = alto/6;
        anchoFila = ancho/6;
        if(grafBuff==null){
            imgBuff = createImage(ancho,alto);
            grafBuff = imgBuff.getGraphics();
        }
        grafBuff.setColor(getBackground());
        grafBuff.fillRect(0, 0, ancho, alto);
        pintarTablero(grafBuff);
        
        g.drawImage(imgBuff, 0, 0, this);
    }
    
    public void pintarTablero(Graphics g){
        
        for(int i=0;i<=6;i++){
            g.setColor(Color.black);
            g.drawLine(0, i*altoFila, ancho, i*altoFila);
            for(int j=0;j<=6;j++){
                g.setColor(Color.black);
                g.drawLine(j*anchoFila, 0,j*anchoFila, alto);
                    if((i+j)%2==0){
                        g.setColor(Color.white);
                        g.fillRect((ancho)-(6-j)*anchoFila,(alto)-(6-i)*altoFila,anchoFila,altoFila);
                    }else{
                        g.setColor(Color.black);
                        g.fillRect((ancho)-(6-j)*anchoFila,(alto)-(6-i)*altoFila,anchoFila,altoFila);
                    }
                }
            }
        }
    
    
    
    @Override
    public void run() {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
}